#!/bin/bash

# shellcheck disable=SC2068
# shellcheck disable=SC2046
# shellcheck disable=SC2086

main() {
	images=(node-exporter:v1.2.2 blackbox-exporter:v0.19.0 kube-rbac-proxy:v0.11.0 prometheus-operator:v0.50.0 configmap-reload:v0.5.0 grafana:8.1.2 kube-state-metrics:v2.2.0 prometheus-adapter:v0.9.0)
	registry=registry.cn-hangzhou.aliyuncs.com/syuee

	for image in ${images[@]}; do
		remote_image_name=$(echo $image | awk -F ":" '{print $1}')
		docker pull $registry/$image

		if test $remote_image_name = "node-exporter"; then
			docker tag $registry/$image quay.io/prometheus/$image
		elif test $remote_image_name = "blackbox-exporter"; then
			docker tag $registry/$image quay.io/prometheus/$image
		elif test $remote_image_name = "kube-rbac-proxy"; then
			docker tag $registry/$image quay.io/brancz/$image
		elif test $remote_image_name = "prometheus-operator"; then
			docker tag $registry/$image quay.io/prometheus-operator/$image
		elif test $remote_image_name = "configmap-reload"; then
			docker tag $registry/$image jimmidyson/$image
		elif test $remote_image_name = "grafana"; then
			docker tag $registry/$image grafana/$image
		elif test $remote_image_name = "kube-state-metrics"; then
			docker tag $registry/$image k8s.gcr.io/kube-state-metrics/$image
		elif test $remote_image_name = "prometheus-adapter"; then
			docker tag $registry/$image k8s.gcr.io/prometheus-adapter/$image
		fi
		docker rmi $registry/$image
	done
}

main
